using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;

using SharpCore.Data;
using SharpCore.Utilities;

namespace Dating.DA
{
	public class MemberGreetingDA
	{
		#region Fields

		protected string connectionStringName;

		#endregion

		#region Constructors
		public MemberGreetingDA()
		{
		}

		public MemberGreetingDA(string connectionStringName)
		{
			ValidationUtility.ValidateArgument("connectionStringName", connectionStringName);

			this.connectionStringName = connectionStringName;
		}

		#endregion

		#region Methods

		/// <summary>
		/// Saves a record to the MemberGreeting table.
		/// </summary>
		public  int Insert(MemberGreeting memberGreeting)
		{
			ValidationUtility.ValidateArgument("memberGreeting", memberGreeting);

			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@TenantID", memberGreeting.TenantID),
				new SqlParameter("@ProfileID", memberGreeting.ProfileID),
				new SqlParameter("@AboutMe", memberGreeting.AboutMe),
				new SqlParameter("@ParnerPreference", memberGreeting.ParnerPreference),
				new SqlParameter("@AdditionalInfo", memberGreeting.AdditionalInfo)
			};

			memberGreeting.MemberGreetingID = Convert.ToInt32(SqlClientUtility.ExecuteScalar(connectionStringName, CommandType.StoredProcedure, "MemberGreetingInsert", parameters));
			return memberGreeting.MemberGreetingID;
		}

		/// <summary>
		/// Updates a record in the MemberGreeting table.
		/// </summary>
		public  int Update(MemberGreeting memberGreeting)
		{
			ValidationUtility.ValidateArgument("memberGreeting", memberGreeting);

			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@MemberGreetingID", memberGreeting.MemberGreetingID),
				new SqlParameter("@TenantID", memberGreeting.TenantID),
				new SqlParameter("@ProfileID", memberGreeting.ProfileID),
				new SqlParameter("@AboutMe", memberGreeting.AboutMe),
				new SqlParameter("@ParnerPreference", memberGreeting.ParnerPreference),
				new SqlParameter("@AdditionalInfo", memberGreeting.AdditionalInfo)
			};

			return(SqlClientUtility.ExecuteNonQuery(connectionStringName, CommandType.StoredProcedure, "MemberGreetingUpdate", parameters));
		}

		/// <summary>
		/// Deletes a record from the MemberGreeting table by its primary key.
		/// </summary>
		public  int Delete(int memberGreetingID, int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@MemberGreetingID", memberGreetingID)
,				new SqlParameter("@TenantID", tenantID)
			};

			return(SqlClientUtility.ExecuteNonQuery(connectionStringName, CommandType.StoredProcedure, "MemberGreetingDelete", parameters));
		}

		/// <summary>
		/// Deletes a record from the MemberGreeting table by a foreign key.
		/// </summary>
		public  int DeleteAllByProfileID(int profileID, int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@ProfileID", profileID)
,				new SqlParameter("@TenantID", tenantID)
			};

			return(SqlClientUtility.ExecuteNonQuery(connectionStringName, CommandType.StoredProcedure, "MemberGreetingDeleteAllByProfileID", parameters));
		}

		/// <summary>
		/// Deletes a record from the MemberGreeting table by a foreign key.
		/// </summary>
		public  int DeleteAllByTenantID(int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@TenantID", tenantID)

			};

			return(SqlClientUtility.ExecuteNonQuery(connectionStringName, CommandType.StoredProcedure, "MemberGreetingDeleteAllByTenantID", parameters));
		}

		/// <summary>
		/// Selects a single record from the MemberGreeting table.
		/// </summary>
		public  MemberGreeting Select(int memberGreetingID, int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@MemberGreetingID", memberGreetingID)
,				new SqlParameter("@TenantID", tenantID)
			};

			using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader(connectionStringName, CommandType.StoredProcedure, "MemberGreetingSelect", parameters))
			{
				if (dataReader.Read())
				{
					return MakeMemberGreeting(dataReader);
				}
				else
				{
					return null;
				}
			}
		}

		/// <summary>
		/// Selects all records from the MemberGreeting table.
		/// </summary>
		public  List<MemberGreeting> SelectAll(int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@TenantID", tenantID)
			};
			using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader(connectionStringName, CommandType.StoredProcedure, "MemberGreetingSelectAll", parameters))
			{
				List<MemberGreeting> memberGreetingList = new List<MemberGreeting>();
				while (dataReader.Read())
				{
					MemberGreeting memberGreeting = MakeMemberGreeting(dataReader);
					memberGreetingList.Add(memberGreeting);
				}

				return memberGreetingList;
			}
		}

		/// <summary>
		/// Selects all records from the MemberGreeting table by a foreign key.
		/// </summary>
		public  List<MemberGreeting> SelectAllByProfileID(int profileID, int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@ProfileID", profileID)
,				new SqlParameter("@TenantID", tenantID)
			};

			using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader(connectionStringName, CommandType.StoredProcedure, "MemberGreetingSelectAllByProfileID", parameters))
			{
				List<MemberGreeting> memberGreetingList = new List<MemberGreeting>();
				while (dataReader.Read())
				{
					MemberGreeting memberGreeting = MakeMemberGreeting(dataReader);
					memberGreetingList.Add(memberGreeting);
				}

				return memberGreetingList;
			}
		}

		/// <summary>
		/// Selects all records from the MemberGreeting table by a foreign key.
		/// </summary>
		public  List<MemberGreeting> SelectAllByTenantID(int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@TenantID", tenantID)

			};

			using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader(connectionStringName, CommandType.StoredProcedure, "MemberGreetingSelectAllByTenantID", parameters))
			{
				List<MemberGreeting> memberGreetingList = new List<MemberGreeting>();
				while (dataReader.Read())
				{
					MemberGreeting memberGreeting = MakeMemberGreeting(dataReader);
					memberGreetingList.Add(memberGreeting);
				}

				return memberGreetingList;
			}
		}

		/// <summary>
		/// Creates a new instance of the MemberGreeting class and populates it with data from the specified SqlDataReader.
		/// </summary>
		protected  MemberGreeting MakeMemberGreeting(SqlDataReader dataReader)
		{
			MemberGreeting memberGreeting = new MemberGreeting();
			memberGreeting.MemberGreetingID = SqlClientUtility.GetInt32(dataReader, "MemberGreetingID", 0);
			memberGreeting.TenantID = SqlClientUtility.GetInt32(dataReader, "TenantID", 0);
			memberGreeting.ProfileID = SqlClientUtility.GetInt32(dataReader, "ProfileID", 0);
			memberGreeting.AboutMe = SqlClientUtility.GetString(dataReader, "AboutMe", String.Empty);
			memberGreeting.ParnerPreference = SqlClientUtility.GetString(dataReader, "ParnerPreference", String.Empty);
			memberGreeting.AdditionalInfo = SqlClientUtility.GetString(dataReader, "AdditionalInfo", String.Empty);

			return memberGreeting;
		}

		#endregion
	}
}
